package cn.itcast.jk.controller.cargo.contract;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.itcast.jk.controller.BaseController;
import cn.itcast.jk.domain.Contract;
import cn.itcast.jk.service.ContractService;

@Controller
public class ContractController extends BaseController{
	@Autowired
	ContractService contractService;
		//列表
		@RequestMapping("/cargo/contract/list.action")
		public String list(Model model) {
			 List<Contract> dataList = contractService.find(null);
			 model.addAttribute("dataList", dataList);	//将数据传递到页面
			 return "/cargo/contract/jContractList.jsp";	//转向页面
		}
		//跳转到新增页面
		@RequestMapping("/cargo/contract/tocreate.action")
		public String tocreate() {
			return "/cargo/contract/jContractCreate.jsp";
		}
		//新增保存
		@RequestMapping("/cargo/contract/insert.action")
		public String insert(Contract contract) {
			contractService.insert(contract);
			return "redirect:/cargo/contract/list.action";	//转向列表的action
		}
		//跳转到修改页面
		@RequestMapping("/cargo/contract/toupdate.action")
		public String toupdate(String id,Model model) {
			Contract contract = contractService.get(id);
			model.addAttribute("obj", contract);
			System.out.println("toupdate=========="+contract.toString());
			return "/cargo/contract/jContractUpdate.jsp";
		}
		//修改保存
		@RequestMapping("/cargo/contract/update.action")
		public String update(Contract contract) {
			System.out.println("update=========="+contract.toString());
			contractService.update(contract);
			return "redirect:/cargo/contract/list.action";	//转向列表的action
		}
		//删除一条
		@RequestMapping("/cargo/contract/deleteById.action")
		public String deleteById(String id) {
			contractService.deleteById(id);
			return "redirect:/cargo/contract/list.action";	//转向列表的action
		}
		//批量删除
		@RequestMapping("/cargo/contract/delete.action")
		public String delete(@RequestParam("id")String[] ids) {
			contractService.delete(ids);
			return "redirect:/cargo/contract/list.action";	//转向列表的action
		}
		//查看
		@RequestMapping("/cargo/contract/toview.action")
		public String toView(String id,Model model) {
			Contract contract = contractService.get(id);
			model.addAttribute("obj", contract);
			return "/cargo/contract/jContractView.jsp";
		}
		//批量上报
		@RequestMapping("/cargo/contract/submit.action")
		public String submit(@RequestParam("id")String[] ids) {
			contractService.submit(ids);
			return "redirect:/cargo/contract/list.action";	//转向列表的action
		}
		//批量取消
		@RequestMapping("/cargo/contract/cancel.action")
		public String cancel(@RequestParam("id")String[] ids) {
			contractService.cancel(ids);
			return "redirect:/cargo/contract/list.action";	//转向列表的action
		}
}
